package com.briup.cms.web.controller;

import com.briup.cms.bean.BaseRole;
import com.briup.cms.service.IBaseRoleService;
import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags="权限管理模块相关接口")
@RequestMapping("/base_role")
public class BaseRoleController {

    @Autowired
    private IBaseRoleService service;

    @ApiOperation("根据id查询角色")
    @GetMapping("/select")
    public Message selectByPrimaryKey(@RequestParam("roleid") Integer id) {
        BaseRole baseRole = service.selectByPrimaryKey(id);
        return MessageUtil.success(baseRole);

    }

    @ApiOperation("添加")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleid", paramType = "query"),
            @ApiImplicitParam(name = "name", paramType = "query")
    })
    @PostMapping("/select")
    public Message insert(BaseRole baseRole) {
        service.insert(baseRole);
        return MessageUtil.success(baseRole);
    }

    @ApiOperation("修改")
    @PutMapping("/update")
    public Message updateByPrimaryKey(BaseRole baseRole) {
        service.update(baseRole);
        return MessageUtil.success(baseRole);
    }

    @ApiOperation("删除")
    @DeleteMapping("/delete")
    public Message deleteByPrimaryKey(Integer id) {
        service.delete(id);
        return MessageUtil.success(id);
    }


    @ApiOperation("查询所有")
    @GetMapping("/find/All")
    public Message findAll() {
        List<BaseRole> findall = service.findAll();
        return MessageUtil.success(findall);

    }
}


